<extend name="Public/base" />
<block name="content">
<center id="tables">
    <button class="button tiny round" onclick="unSelect()">反选</button>
    <button class="button tiny round" onclick="delLot()">删除</button>
    <table  >
    <theat>
        <th><input type="checkbox" onclick="selectAll(this)"></th>
        <th style="text-align:center">编号</th>
        <th style="text-align:center">姓名</th>
        <th style="text-align:center">性别</th>
        <th style="text-align:center">邮箱</th>
        <th style="text-align:center">电话</th>
        <th style="text-align:center">锁定</th>
        <th style="text-align:center">操作</th>
    </theat>
<tbody id="tbodys">
<volist name="navs" id="v">
    <tr id="row_<{$v.student_id}>">
        <td><input value="<{$v.student_id}>" class="rowcb" type="checkbox"></td>
        <td style="text-align:center" ><{$v.student_id}></td>
        <td style="text-align:center"><{$v.sname}></td>
        <td style="text-align:center"><{$v.val}></td>
        <td style="text-align:center"><{$v.email}></td>
        <td style="text-align:center"><{$v.mtel}></td>
        <td>
            <div class="switch tiny round">
                <input onclick="lock(this)" value="<{$v.student_id}>" id="lock_<{$v.student_id}>" type="checkbox"  <{$v['lock']?'checked':''}>>
                <label for="lock_<{$v.student_id}>"></label>
            </div>
        </td>
        <td>
            <a class="button tiny round" href="<{:U('Student/editStudent?id='.$v['student_id'])}>"><i class="fi-wrench"> </i>编辑</a>
        </td>
    </tr>
   </volist>
</tbody>
</table>
    <div id="page"  style="text-align:center">
        <for start="1" end="$pages+1" >
            <span data-val="<{$i}>" style="cursor:pointer"><{$i}>&nbsp;&nbsp;</span>
        </for>
    </div>
</center>
<div align="right" style="margin-right:5%">
    <button class="button tiny radius" id="addUser" >添加一条新的记录</button>
    <center>
        <fieldset id="addUserForm" style="display: none;">
            <legend>学生信息添加表</legend>
            <form action="<{:U('doAddSave')}>" method="post">
            <table border="1">
               <tr>
                   <td>昵&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;称</td>
                   <td><input type="text" name="nick" style="height:25px"></td>
                   <td>姓&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;名</td>
                   <td><input type="text" name="sname" style="height:25px"></td>
               </tr>
               <tr>
                   <td>密&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;码</td>
                   <td><input type="password" name="pwd" style="height:25px"></td>
                   <td>年&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;龄</td>
                   <td><input type="text" name="age" style="height:25px"></td>
               </tr>
               <tr>
                   <td>性&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;别</td>
                   <td>
                       <center>
                           <input type="radio" name="sex" value="1">男
                           <input type="radio" name="sex" value="2">女
                       </center>
                   </td>
                   <td>手&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;机</td>
                   <td><input type="text" name="mtel" style="height:25px"></td>
               </tr>
               <tr>
                   <td>备用电话</td>
                   <td><input type="text" name="btel" style="height:25px"></td>
                   <td>固&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;话</td>
                   <td><input type="text" name="tel" style="height:25px"></td>
               </tr>
                <tr>
                    <td>家庭住址</td>
                    <td><input type="text" name="home_addr" style="height:25px"></td>
                    <td>拟定班级</td>
                    <td><input type="text" name="class" style="height:25px"></td>
                </tr>
               <tr>
                   <td>身&nbsp;&nbsp;份&nbsp;证</td>
                   <td><input type="text" name="id_card" style="height:25px"></td>
                   <td>毕业时间</td>
                   <td><input type="text" name="leave_time" style="height:25px"></td>
               </tr>
               <tr>
                   <td>邮&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;箱</td>
                   <td><input type="email" name="email" style="height:25px"></td>
                   <td>&nbsp;&nbsp;&nbsp;QQ&nbsp;&nbsp;&nbsp;</td>
                   <td><input type="text" name="QQ" style="height:25px"></td>
               </tr>
               <tr>
                   <td>教育程度</td>
                   <td><input type="text" name="education" style="height:25px"></td>
                   <td>学&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;校</td>
                   <td><input type="text" name="school" style="height:25px"></td>
               </tr>
               <tr>
                   <td>专&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;业</td>
                   <td><input type="text" name="major" style="height:25px"></td>
                   <td>是否知道php</td>
                   <td>
                       <center>
                           <input type="radio" name="know_php" value="Y">是
                           <input type="radio" name="know_php" value="N">否
                       </center>
                   </td>
               </tr>
               <tr>
                   <td>是否尝试过php</td>
                   <td>
                       <center>
                           <input type="radio" name="try_php" value="Y">是
                           <input type="radio" name="try_php" value="N">否
                       </center>
                   </td>
                   <td>了解PHP的途径</td>
                   <td>
                       <center>
                           <input type="checkbox" name="learn_way[]" value="a">学校课程
                           <input type="checkbox" name="learn_way[]" value="b">网站书籍
                           <input type="checkbox" name="learn_way[]" value="c">系统培训
                       </center>
                   </td>
               </tr>
               <!--<tr>-->
                   <!--<td></td>-->
                   <!--<td><input type="text" name="" style="height:25px"></td>-->
                   <!--<td></td>-->
                   <!--<td><input type="text" name="" style="height:25px"></td>-->
               <!--</tr>-->
           </table>
                <input type="hidden" name='ctime' value="<php>echo time();</php>">
            <input type="submit" value="保存" class="button tiny radius">
            <button type="button" id="closeUserForm" class="button tiny radius">关闭</button>
            </form>
        </fieldset>
        </center>
</div>
<script>
    function lock(obj) {
        var id = $(obj).val();
        var lockval = $(obj).prop('checked')?1:0;
        $.post('<{:U("doEditStudent")}>',{student_id:id,lock:lockval});
    }
//    $(".a_upload").on("change","input[type='file']",function(){
//        var filePath=$(this).val();
//        if(filePath.indexOf("jpg")!=-1 || filePath.indexOf("png")!=-1){
//            $(".fileerrorTip").html("").hide();
//            var arr=filePath.split('\\');
//            var fileName=arr[arr.length-1];
//            $(".showFileName").html(fileName);
//        }else{
//            $(".showFileName").html("");
//            $(".fileerrorTip").html("您未上传文件，或者您上传文件类型有误！").show();
//            return false
//        }
//    })
$(document).ready(function() {
    $(document).foundation();
})
$('#addUser').click(function(){
    $('#tables').hide();
    $('#editUserForm').hide();
    $('#addUser').hide();
    $('#addUserForm').show();
});
$('#closeUserForm').click(function(){
    $('#addUserForm').hide();
    $('#tables').show();
    $('#addUser').show();
});
//$('#saveUser').click(function(){
//    //收集用户输入内容
//    var data,newRow;
//    data = {
//        uname:$('#addUserForm [name=uname]').val(),
//        pwd:$('#addUserForm [name=pwd]').val(),
//        uemail:$('#addUserForm [name=uemail]').val(),
//        utel:$('#addUserForm [name=utel]').val(),
//    };
//    console.log(data);
//    $.post('<{:U("doAdd")}>',data,function (res) {
//        if(res.error===0){
//            data = res.data;
//            newRow = '<tr id="row_'+data.uid+'">'+'<td><input value='+data.uid+'class="rowcb" type="checkbox"></td>'+'<td style="text-align:center">'+data.uid+'</td><td style="text-align:center">'+data.uname+'</td><td style="text-align:center">'+data.uemail+'</td><td style="text-align:center">'+data.utel+'</td>' +
//                    '<td style="text-align:center"><button class="button tiny round" onclick="dell(('+data.uid+')"><i class="fi-trash"> </i> 删除</button> <button class="button tiny round" onclick="editUser('+data.uid+')"><i class="fi-wrench"> </i>编辑</button></td></tr>';
//            $('#tables').append(newRow);
//        }else{
//            alert(res.msg);
//        }
//    });
//    $('#addUserForm').hide();
//    $('#editUserForm').hide();
//    $('#tables').show();
//    $('#addUser').show();
//});
function delLot() {
    if($('#tables tbody .slct:checked')['length']){
        if(confirm('确定删除吗?')){
            var ids = $('#tables tbody .slct:checked').map(function () {
                $(this).parent().parent().remove();
                return $(this).val();
            });
            ids  = ids.get().join();
            $.post('<{:U("doDelStudent")}>',{ids:ids},function (data) {
                alert(data.msg);
            });
        }}}
    $('#page span').click( function () {
        var pagenum = $(this).attr('data-val');
        $.get('<{:U("getShow")}>',{p:pagenum},function (data) {
            var html='';
            for(var i in data){
                html +='<tr id="row_'+data[i].student_id+'">'
                            +'<td><input value="'+data[i].student_id+'" class="rowcb" type="checkbox"></td>'
                            +'<td style="text-align:center" >'+data[i].student_id+'</td>'
                            +'<td style="text-align:center">'+data[i].sname+'</td>'
                            +'<td style="text-align:center">'+data[i].val+'</td>'
                            +'<td style="text-align:center">'+data[i].email+'</td>'
                            +'<td style="text-align:center">'+data[i].mtel+'</td>'
                            +'<td>'
                            +'<div class="switch tiny round">'
                            +'<input onclick="lock(this)" value="'+data[i].student_id+'" id="lock_'+data[i].student_id+'" type="checkbox"'+data[i]['lock']?'checked>':'>'
                            +'<label for="lock_'+data[i].student_id+'"></label>'
                            +'</div>'
                            +'</td>'
                            +'<td>'
                            +'<button class="button tiny round" onclick="editUser('+data[i].student_id+')"><i class="fi-wrench"> </i>编辑</button>'
                            +'</td>'
                            +'</tr>';
            }
            $('#tables #tbodys').html(html);
        });
    } );
function selectAll(obj) {
    var checkstatu = $(obj).prop('checked');
    $('.rowcb').prop('checked',checkstatu);
}
function unSelect() {
    $('.rowcb').prop('checked',function (index,val) {
        return !val;
    });
}
</script>
</block>